package com.example.my_self_view

import android.app.Activity
import android.content.Intent
import android.graphics.Rect
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.my_self_view.calendar.CalendarActivity
import com.example.my_self_view.databinding.ActivityInitBinding
import com.example.my_self_view.init.ButtonAdapter
import com.example.my_self_view.list.ListActivity
import com.example.my_self_view.list2.List2Activity
import com.example.my_self_view.lockpattern.LockPatternActivity
import com.example.my_self_view.pdf.PdfActivity
import com.example.my_self_view.practice1.Test1Activity
import com.example.my_self_view.practice2.Test2Activity
import com.example.my_self_view.ratingbar.RatingBarTestActivity
import com.example.my_self_view.tablayout.TabLayoutActivity
import com.example.my_self_view.viewdrag.ViewDragActivity

class InitActivity: AppCompatActivity() {

    private lateinit var binding: ActivityInitBinding
    private val adapter by lazy { ButtonAdapter() }
    private val data by lazy { arrayListOf<Pair<String, () -> Unit>>() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityInitBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.rvMenu.layoutManager = LinearLayoutManager(this)
        binding.rvMenu.adapter = adapter
        binding.rvMenu.addItemDecoration(object : RecyclerView.ItemDecoration(){
            override fun getItemOffsets(
                outRect: Rect,
                view: View,
                parent: RecyclerView,
                state: RecyclerView.State
            ) {
                super.getItemOffsets(outRect, view, parent, state)
                outRect.bottom = 10
            }
        })
        // canvas切割文字
        addData("canvas切割文字", MainActivity::class.java)
        // viewPager例子
        addData("viewPager例子", ViewPagerActivity::class.java)
        // behavior例子
        addData("behavior例子", com.example.my_self_view.behavior.MainActivity::class.java)
        // 随便写的日历，不会优化
        addData("随便写的日历，不会优化", CalendarActivity::class.java)
        // listView例子一
        addData("listView例子一", ListActivity::class.java)
        // listView例子二
        addData("listView例子二", List2Activity::class.java)
        // 图案锁例子
        addData("图案锁例子", LockPatternActivity::class.java)
        // 双颜色环形进度条
        addData("双颜色环形进度条", Test1Activity::class.java)
        // 多图形转换Loading
        addData("多图形转换Loading", Test2Activity::class.java)
        // 评分条
        addData("评分条", RatingBarTestActivity::class.java)
        // 瀑布流标签Layout
        addData("瀑布流标签Layout", TabLayoutActivity::class.java)
        // viewDrag例子
        addData("viewDrag例子", ViewDragActivity::class.java)
        // pdf渲染简单例子
        addData("pdf渲染简单例子", PdfActivity::class.java)
        adapter.data = data
    }

    private fun addData(text: String, activity: Class<*>) {
        data.add(
            text to
                    {startActivity(Intent(this@InitActivity, activity))}
        )
    }
}